package com.utils.config;

import java.io.File;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.utils.PropertiesUtil;
import com.utils.UUIDGeneratorUtil;
import com.utils.date.DateUtil;

public class CommonConfig {

	/**
	 * 配置文件地址
	 */
	private static final String config="config.properties";
	
	private static final String charset="utf-8";

	public static String getCachePath() {
		String cachePath = PropertiesUtil.getProperties(config, charset).getProperty("path.cache");
		if(StringUtils.isNotBlank(cachePath)){
			return cachePath.replace("\\", File.separator).replace("/", File.separator);
		}
		return null;
	}
	
	public static String getUplodCachePath() {
		String uploadCachePath = getCachePath() + File.separator + 
								"upload"+ File.separator + 
								DateUtil.format(new Date(), "yyyy-MM-dd")+ File.separator + 
								UUIDGeneratorUtil.getUUID();
		return uploadCachePath;
	}

	public static String getWebPath(){
//		String webPath = getCachePath(); 
//		if(StringUtils.isNotBlank(webPath)){
//			return webPath;
//		}else{
//		}
		String classPath = CommonConfig.class.getClassLoader().getResource("").getPath();	
		int index = classPath.indexOf("WEB-INF");
		if(index > -1){
			String webPath = classPath.substring(0, index);
//			webPath = webPath.replace("\\", File.separator).replace("/", File.separator);
//			if(webPath.indexOf(File.separator) == 0){
//				webPath = webPath.substring(1);
//			}
			return webPath.replace("\\", File.separator).replace("/", File.separator);			
		}
		return getCachePath();
	}	
}
